import request from '@/utils/request'

// 创建订单接口
export const createOrderAPI = (data) => {
  return request({
    url: '/mall-order/order/create-order',
    method: 'POST',
    data
  })
}
// 获取订单详情页
export const getOrderAPI = (orderSn) => {
  return request({
    url: `/mall-order/order/get-order/${orderSn}`
  })
}
// 我的订单获取
export const getUserOrderAPI = (params) => {
  return request({
    url: '/mall-order/order/get',
    method: 'GET',
    params
  })
}
export const getPayAPI = (orderId) => {
  return request({
    url: `/mall-order/order/aliPay/${orderId}`,
    method: 'GET'
  }).catch(error => {
    console.error('支付请求失败详情:', {
      status: error.response?.status,
      data: error.response?.data,
      headers: error.response?.headers
    });
    throw error;
  });
}

// 根据订单号获取支付页面（如果后端需要）
export const getPayBySnAPI = (orderSn) => {
  return request({
    url: `/mall-order/order/aliPayOrder?orderSn=${orderSn}`,
    method: 'GET'
  })
}

// 在 @/apis/order.js 中添加取消订单API
export const cancelOrderAPI = (orderNo) => {
  return request({
    url: `/mall-order/order/cancel/${orderNo}`,
    method: 'GET' // 根据实际接口设计选择 PUT/POST
  })
}

export const getOrderDetailAPI = (orderNo) => {
  return request({
    url: `/mall-order/order/detail/${orderNo}`,
    method: 'GET'
  })
}